<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/js/thirdparty/jquery.js"></script>
    <script src="global.js"></script>
    <style>
        .div-login {
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            background-color: rgba(0, 0, 0, .4);
            display: none;
            z-index: -1;
        }

        .div-login.active {
            display: block;
            z-index: 9999;
        }
    </style>
</head>
<body>
<input type="text" id="username" placeholder="用户名"/>
<input type="password" id="password" placeholder="密码"/>
<button id="btnSignIn">登录</button>
<div id="divLogin" class="div-login">
    <div>login</div>
</div>
<script>
    var iptUsername = $('#username');
    var iptPassword = $('#password');
    var btnSignIn = $('#btnSignIn');
    var divLogin = $('#divLogin');
    var username = null, password = null;
    btnSignIn.click(function () {
        divLogin.addClass('active');
        username = iptUsername.val();
        password = iptPassword.val();
        signIn();
    });

    function signIn() {
        $.ajax({
            url: "http://" + baseURL + ":" + basePort + "/logout",
            // url:"http://192.168.31.181:8181/logout",
            type: 'POST',
            success: function (data) {
                divLogin.removeClass('active');
                console.log('logout success========================')
                console.log('baseURL========================', baseURL)
                console.log('basePort========================', basePort)
                divLogin.addClass('active');
                $.ajax({
                    url: "http://" + baseURL + ":" + basePort + "/login.jsp",
                    // url:"http://192.168.31.181:8181/login.jsp",
                    type: "POST",
                    data: {
                        username: username,
                        password: password
                    },
                    success: function (data) {
                        console.log('data:', data);
                        if (data.success) {
                            window.sessionStorage.setItem('access_token', data.access_token);
                            window.location.href = 'index3.html';
                        } else {
                            alert('Error');
                            divLogin.removeClass('active');
                        }
                    },
                    error: function (err) {
                        console.log('err:', err)
                    }
                });
            },
            error: function () {
                divLogin.removeClass('active');
            }
        })
    }
</script>
</body>
</html>
